﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BioBooking.Client.Screens
{
    public partial class Wizard : UserControl
    {
        public List<UserControl> Steps { get; set; }
        public bool CircularEnabled { get; set; }
        public int DefaultIndex { get; set; }

        private int currentIndex;
        public int CurrentIndex 
        {
            get
            {
                return currentIndex;
            }

            set
            {
                SetCurrentViewIndex(value);
            }
        }

        public Wizard() : this(new List<UserControl>())
        {
            InitializeComponent();
        }

        public Wizard(List<UserControl> steps)
        {
            InitializeComponent();
            this.Steps = steps;

            DefaultIndex = 0;
            currentIndex = 0;
            SetCurrentViewIndex(currentIndex);
        }

        public void Next()
        {
            CurrentIndex = CurrentIndex + 1;
        }

        public void Reset()
        {
            CurrentIndex = DefaultIndex;
        }

        public void Previous()
        {
            CurrentIndex = currentIndex - 1;
        }

        public void InsertNextView(UserControl control)
        {
            this.Steps.Insert(CurrentIndex + 1, control);
            SetCurrentViewIndex(currentIndex + 1);
        }

        public void SetCurrentViewIndex(int index)
        {
            if (index < 0)
            {
                if (CircularEnabled)
                    index = Steps.Count - 1;

                index = 0;
            }

            if (index > Steps.Count - 1)
            {
                if (CircularEnabled)
                    index = 0;

                index = Steps.Count - 1;
            }

            this.currentIndex = index;
            if (Steps.Count > 0)
            {
                ccWizardContent.Content = Steps[index];
            }
        }

    }
}
